home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / STFX-soundsystemdisk.adf / sources / ZOUNDMON.CFILES / Player.c < prev    next >
Text File  |  1988-01-20  |  13KB  |  303 lines

  1. #asm
  2.   global     _AudioTemp,200    ;
  3.   public     _KillZound        ;
  4.   public     _SetUpInterrupt   ;
  5. newlevel3                      ; This is the new interrupt
  6.   btst.b     #5,$dff01f        ; Was it a VertB ??
  7.   beq        backtoexec        ; If not let exec process it
  8.   movem.l    D0-D7/A0-A6,-(A7) ; Save registers
  9.   bsr        _intrMusic        ; Our music !
  10.   movem.l    (A7)+,D0-D7/A0-A6 ; Prepare to reenter exec
  11. backtoexec   dc.w       $4ef9  ; This means JMP
  12. oldlevel3    dc.l       0      ; So jump to exec interrupt handlers
  13. trueA4       dc.l       0      ; Storage for A4
  14.  
  15. _SetUpInterrupt:
  16.   move.l  #49,D0           ;
  17.   lea     _AudioTemp,A0    ; First we clean up
  18. clearaudio                 ; The 200 audio bytes
  19.   clr.l   (A0)+            ; This is handy for the editor
  20.   dbra    D0,clearaudio    ;
  21.   move.w  #1,_AudioTemp+6  ; Set Audio[i]->DMA
  22.   move.w  #2,_AudioTemp+46 ;
  23.   move.w  #4,_AudioTemp+86 ;
  24.   move.w  #8,_AudioTemp+126;
  25.   clr.w   $dff0a8          ; kill voices
  26.   clr.w   $dff0b8          ;  ,,
  27.   clr.w   $dff0c8          ;  ,,
  28.   clr.w   $dff0d8          ;  ,,
  29.   clr.b   _partvec         ; partvec = 0
  30.   move.b  _StartTab,_tabvec; start position of song
  31.   move.b  _speed,D0        ;
  32.   sub.b   #1,D0            ;
  33.   move.b  D0,_count        ;
  34.   lea     trueA4,A0        ; Save A4
  35.   move.l  A4,(A0)          ; To be used in interrupt
  36.   move.w  #$4000,$dff09a   ; Disable interrupts
  37.   lea     oldlevel3,A0     ; Get old interrupt and
  38.   move.l  $6c,(A0)         ; Store somewhere
  39.   move.l  #newlevel3,$6c   ; Replace it by our interrupt
  40.   move.w  #$c000,$dff09a   ; Enable interrupts
  41.   rts
  42.  
  43. _KillZound:
  44.   move.w  #$4000,$dff09a   ; Disable interrupts
  45.   move.l  oldlevel3,$6c    ; Restore old interrupt vector
  46.   move.w  #$c000,$dff09a   ; Enable interrupts
  47.   move.w  #15,$dff096      ; Switch off DMA
  48.   rts
  49.  
  50. _intrMusic
  51.   move.l   trueA4,A4       ; Get the right A4 !
  52.   addq.b   #1,_count       ; Count++;
  53.   move.b   _count,D1       ; Compare count with speed;
  54.   cmp.b    _speed,D1       ; If equal:
  55.   beq      newvoices       ;     start a new note
  56.   tst.w    _dmaconhulp     ; Any voices to be switched on ?
  57.   beq      nodma           ; If not: skip a while
  58.   move.w   _dmaconhulp,D0  ; Get the voices to be switched on
  59.   or.w     #$8200,D0       ; Prepare to set some bits
  60.   move.w   D0,$dff096      ; Let the sound come out!
  61.   clr.w    _dmaconhulp     ; clearit !
  62. nodma
  63.   movea.l  #$dff0a0,A3     ; Get voices's registerbase
  64.   move.l   #20,D0          ; This waiting loop is nessacary
  65. wait                       ; because the hardware ain't fast
  66.   dbra     D0,wait         ; enough to change voice1's replen quickly
  67.   move.l   #3,D5           ; We have 4 voices to handle so 3 ! (Thanx Dave!!)
  68.   lea      _AudioTemp,A2   ; Get audio in A2
  69. loop
  70.   bsr      specials        ;
  71.   adda.l   #40,A2          ; Let A2 point to next audiohulp
  72.   adda.l   #16,A3          ; And A1 to next voice-registers
  73.   dbra     D5,loop         ; Any voices left ? then handle them !
  74.   rts                      ; Leave my music routine
  75.  
  76. specials
  77.   btst.b   #0,21(A2)       ; Do we have Arpeggio here ?
  78.   beq      noarpeggio      ; Yes it is beq here !
  79.   btst.b   #1,21(A2)       ; If both bit 0 and bit 1 are set
  80.   bne      superslide      ; Then use my superslide routine
  81.   add.w    #1,30(A2)       ; Increment arpeggio counter
  82.   btst.b   #0,31(A2)       ; If odd : resume loop
  83.   bne      noslidehere     ;    else: poke new period
  84.   move.w   30(A2),D1       ; Get count in D1
  85.   asr.l    #1,D1           ; Divide by 2
  86.   divu.w   #3,D1           ;
  87.   swap     D1              ; Get count%3 in D1
  88.   clr.l    D2              ;
  89.   move.b   22(A2,D1.w),D2  ; Get current arpdata
  90.   add.b    20(A2),D2       ; Add audio->basenote in D2
  91.   asl.l    #1,D2           ; Mutiply with 2 because periods are words
  92.   lea      _Periods,A0     ; Get the Periods table
  93.   move.w   (A0,D2.l),6(A3) ; Poke the period
  94.   bra      noslidehere     ;
  95. superslide
  96.   move.w   30(A2),D0       ; Compare count
  97.   cmp.w    34(A2),D0       ; With Maxcount
  98.   beq      noslidehere     ; If ready: exit
  99.   addq.w   #1,D0           ;
  100.   move.w   D0,30(A2)       ; Increment counter
  101.   move.w   32(A2),D2       ; Get the Period difference
  102.   muls.w   D0,D2           ; Multiply with counter
  103.   divs.w   34(A2),D2       ; Divide by maxcount
  104.   add.w    4(A2),D2        ; Add the period to it.
  105.   move.w   D2,6(A3)        ; Let the sound come out.
  106.   bra      noslidehere     ; 
  107. noarpeggio
  108.   btst.b   #1,21(A2)       ; Perhaps a Sliding note?
  109.   beq      noslidehere     ;
  110.   move.w   2(A2),D1        ; Get slidespeed in D1
  111.   add.w    4(A2),D1        ; Add the period to it
  112.   move.w   D1,4(A2)        ; Store it in the audio period
  113.   move.w   D1,6(A3)        ; Let the sound come out!
  114. noslidehere
  115.   move.l   16(A2), (A3)    ; Poke audio->start
  116.   move.w   10(A2),4(A3)    ; Poke audio->length
  117.   rts
  118.  
  119. GetVolume
  120.   clr.l     D0             ;
  121.   move.w    26(A2),D0      ; Put audio->Samplevol in D0
  122.   move.l    D4,D1          ; Put data in D1
  123.   lsr.w     #8,D1          ; Shift it to get the Volume-add
  124.   ext.w     D1             ; - may be negative
  125.   add.w     D1,D0          ; Add it to the volume we've got
  126.   move.b    1(A5),D1       ; Get intab->volume
  127.   ext.w     D1             ; Extend to word
  128.   add.w     D1,D0          ; Add it to the volume we've got
  129.   cmp.w     #64,D0         ; If it exceeds the maximum
  130.   bcs       volumeOK       ;   legal volume then
  131.   tst.w     D0             ;
  132.   bmi       negative       ;
  133.   move.w    #64,D0         ; Put the volume on maximum
  134.   bra       volumeOK       ;
  135. negative
  136.   clr.w     D0             ;
  137. volumeOK
  138.   move.w    D0,(A2)        ; Store it in audio->volume
  139.   rts
  140.  
  141. newvoices
  142.   clr.b     _count         ;
  143.   move.l    #3,D5          ; 4 Voices...So set it to 3 (Thanx dave!)
  144.   lea       _AudioTemp,A2  ;
  145.   movea.l   #$dff0a0,A3    ; Install register voice base
  146.   lea       _Table,A5      ; Get Tablebase
  147.   clr.l     D0             ;
  148.   move.b    _tabvec,D0     ; Add 16*tabvec
  149.   asl.l     #4,D0          ;
  150.   adda.l    D0,A5          ;
  151. nvs
  152.   btst.b    #0,29(A2)      ; Test if data is used for sliding
  153.   beq       allOK          ;
  154.   bclr.b    #0,29(A2)      ; Clear flag.
  155.   bsr       specials       ; Do sliding ea
  156.   bra       dontplayit     ; Handle next voice
  157. allOK
  158.   clr.l     D0             ;
  159.   move.b    (A5),D0        ; Intab->partno in D0
  160.   asl.l     #7,D0          ; Multiply with 128   (32 longwords)
  161.   clr.l     D1             ;
  162.   move.b    _partvec,D1    ; Partvec in D1
  163.   asl.l     #2,D1          ; Multiply with 4
  164.   add.l     D1,D0          ; Add it to the offset
  165.   lea       _Parts,A1      ; Get partsbase in A1
  166.   move.l    (A1,D0.l),D4   ; Get some usefull data out of it
  167.   move.l    4(A1,D0.l),D7  ; Get next Data in D7
  168.   move.l    D4,D0          ; Data in D0
  169.   move.l    #24,D1         ; Shift it 24 to the right
  170.   asr.l     D1,D0          ; Now got the note to be played
  171.   and.b     #$3f,D0        ;
  172.   bne       newnote        ; We don't play Zero's
  173.   bsr       specials       ; Do the effects
  174.   bra       dontplayit     ; 
  175. newnote
  176.   move.b    D0,20(A2)      ; Store it in audio->basenote
  177.   move.l    D4,D0          ; Get data in D0
  178.   and.l     #$f0000,D0     ; And it to get the control nibble
  179.   move.l    #16,D1         ; Shift it 16 bits to the right
  180.   asr.l     D1,D0          ;
  181.   move.b    D0,21(A2)      ; And store it in audio->control
  182.   btst.b    #2,21(A2)      ; Is the NONOTEADD flag set ?
  183.   bne       nonoteadd      ;
  184.   move.b    3(A5),D0       ; Else add intab->noteadd
  185.   add.b     D0,20(A2)      ; To audio->basenote
  186. nonoteadd
  187.   clr.w     D0             ; Clever Aztec Code
  188.   move.b    20(A2),D0      ;   Which I can't improve
  189.   asl.w     #1,D0          ;   ;
  190.   lea       _Periods,A0    ;   ;
  191.   move.w    (A0,D0.w),4(A2);   ;
  192.   btst.b    #0,21(A2)      ; Do we have an arpeggio here ?
  193.   beq       noarp          ;
  194.   btst.b    #1,21(A2)      ; Do we have UltraSlide ?
  195.   bne       ultraslide     ;
  196.   move.l    D4,D0          ; Get data in D0
  197.   lsr.b     #4,D0          ; Put data>>4 in arpdata1
  198.   move.b    D0,23(A2)      ;
  199.   move.l    D4,D0          ; Get Data again
  200.   and.b     #15,D0         ; Use the rightmost nibble
  201.   move.b    D0,24(A2)      ; Store it in arpdata2
  202.   clr.w     30(A2)         ; Reset counter
  203.   bra       noslide        ;
  204. ultraslide
  205.   bset.b    #0,29(A2)      ; Notice that next data is used for sliding
  206.   move.l    #24,D0         ;
  207.   move.l    D7,D1          ;
  208.   asr.l     D0,D1          ; Get Next note to be played
  209.   btst.l    #18,D7         ; Test for NONOTEADD flag
  210.   bne       ohboy          ; If not set:
  211.   add.b     3(A5),D1       ; Add the noteadd to it
  212. ohboy
  213.   and.w     #$3f,D1        ; Dump the DMA-bits
  214.   asl.w     #1,D1          ;
  215.   lea       _Periods,A0    ;
  216.   move.w    (A0,D1.w),D0   ; Next Period to be played
  217.   sub.w     4(A2),D0       ; Substract the current period
  218.   move.w    D0,32(A2)      ; Store it in period difference
  219.   clr.w     30(A2)         ; Reset counter
  220.   move.w    D4,D0          ; Get current data
  221.   and.w     #$ff,D0        ; Extract time
  222.   clr.w     D1             ;
  223.   move.b    _speed,D1      ; Multiply by speed
  224.   mulu.w    D1,D0          ;
  225.   move.w    D0,34(A2)      ; Store it in maxcount
  226.   bra       noslide        ;
  227. noarp
  228.   btst.b    #1,21(A2)      ; Do we want slide here ?
  229.   beq       noslide        ;
  230.   move.l    D4,D0          ; Get data in D0
  231.   and.w     #$ff,D0        ; Use the rightmost byte
  232.   ext.w     D0             ; Extend it to a word
  233.   move.w    D0,2(A2)       ; Store it in audio->slidespeed
  234. noslide
  235.   move.l    D4,D0          ; Get Data again
  236.   and.l     #$f00000,D0    ; Extract sample
  237.   move.w    #20,D1         ; By shifting it 20 
  238.   asr.l     D1,D0          ; To the right
  239.   beq       oldsample      ; If zero, use old sample
  240.   btst.b    #3,21(A2)      ; Is the NOINSTRADD bit set ?
  241.   bne       noinstradd     ;
  242.   add.b     2(A5),D0       ; Add the instrument add to tempbyte
  243. noinstradd 
  244.   bne       newsample      ;
  245. oldsample                  ;
  246.   bsr       GetVolume      ; Get the volume
  247.   bra       nextvoice      ; If zero, Use the old Sample
  248. newsample
  249.   cmp.b     37(A2),D0      ; Maybe user made stupid music data...
  250.   beq       oldsample      ; We do allready have this sample !!!
  251.   move.b    D0,37(A2)      ; Save sampleno
  252.   sub.l     #1,D0          ; Calculate new sample
  253.   mulu.w    #54,D0         ;
  254.   lea       _Sample,A6     ; Put it in A6
  255.   adda.l    D0,A6          ;
  256.   move.b    44(A6),D0      ;   !      Nasty things happen
  257.   ext.w     D0             ;  !!!  if you use a byte address
  258.   move.w    D0,26(A2)      ; !!!!!     as a word adress
  259.   bsr       GetVolume      ; Well, that's clear (isn't it ?)
  260.   move.l    (A6),12(A2)    ; Put Sample's start in audio->samplestart
  261.   move.w    46(A6),8(A2)   ; Put Sample's length in audio->length
  262.   move.w    48(A6),10(A2)  ; Put Sample's replen in audio->oneblowlen
  263.   clr.l     D0             ;
  264.   move.w    50(A6),D0      ; Get Sample's restart data in D0
  265.   asl.l     #1,D0          ; Mutiply with 2
  266.   add.l     12(A2),D0      ; Add audio->samplestart to it
  267.   move.l    D0,16(A2)      ; And store it in audio->restart
  268. nextvoice
  269.   btst.l   #31,D4          ; Check for DMA off/on switch
  270.   beq      DMAonoff        ;
  271.   move.b   37(A2),D0       ; Check for sample yet to play
  272.   cmp.b    36(A2),D0       ; If equal to last used sample
  273.   beq      nonewDMA        ; Then don't start it.
  274.   move.b   D0,36(A2)       ; Update last used sample
  275. DMAonoff                   ; Switch it on anyway
  276.   move.w    6(A2),$dff096  ; Turn voice off
  277.   cmp.b    #63,20(A2)      ; If(audio->basenote==63)
  278.   beq      dontplayit      ;
  279.   move.w   6(A2),D0        ; dmaconhulp|=audio->dma;
  280.   or.w     D0,_dmaconhulp  ;
  281.   move.l   12(A2), (A3)    ; Poke Samplestart
  282.   move.w    8(A2),4(A3)    ; Poke SampleLength
  283. nonewDMA
  284.   move.w    4(A2),6(A3)    ; Poke Period
  285.   move.w     (A2),8(A3)    ; Poke Volume
  286. dontplayit                 ;
  287.   add.l    #40,A2          ; Get new AudioTemp
  288.   add.l    #16,A3          ; Get new voice's registerbase
  289.   addq.l   #4,A5           ; Get new intab
  290.   dbra     D5,nvs          ; Have we processed all voices allready?
  291.   addq.b   #1,_partvec     ; Next note
  292.   cmpi.b   #32,_partvec    ; Are at the end of this part?
  293.   bne      exit            ; If not: exit
  294.   clr.b    _partvec        ; Install new part
  295.   add.b    #1,_tabvec      ; Next tabel position
  296.   move.b   _tabvec,D1      ;
  297.   cmp.b    _EndTab,D1      ; Are we at the end of the song?
  298.   bne      exit            ; If not: exit
  299.   move.b  _StartTab,_tabvec; Restart song
  300. exit
  301.   rts
  302. #endasm
  303.